Skip to content

Native: MLX core on upstream MLX main 1ba7f969 (2026-10-30), NDEBUG in release - #1681

Draft
jonathan308 wants to merge 4 commits into
devfrom
perf/mlx-upstream-2026-10-30
Draft

jonathan308 wants to merge 4 commits into
devfrom
perf/mlx-upstream-2026-10-30

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Kept out of 0.10.11; a candidate for 0.10.12 once the measurement below clears it (draft). On the pair, Qwen3.8 27B
TP2 decoded about 5% slower per request with 4 concurrent requests on this core (22.5 tok/s against 23.7 and 23.6 in two
runs on the previous core), and about 2% slower with 8 (12.3 against 12.5 and 12.6). That is one run of this core; the
cause is not known yet. One-request decode, prefill and GLM-5.3-Flash were unchanged. Before this merges: confirm or
refute that, and check the other served models on this core. #1680 (the Qwen layout speed-up) does not need this PR.

Status (2026-11-09, PR sweep)

Measurement to clear it for 0.10.12 (needs an M5 Ultra window and the Studio; no GPU work on Mac A)

Two provider builds from the same dev tree, differing only in libs/mlx and libs/mlx-swift: P (72dffa2d /
c633d221) and N (this PR). Each gets its own source-matched metallib (scripts/fetch-metallib.sh), and both
metallib hashes are recorded.

  1. M5 Ultra pair, about 2.5 h: confirm or refute the 4-concurrent result. Qwen3.8 27B TP2 at 1, 2, 4 and 8 concurrent
    requests; GLM-5.3-Flash TP2 at 1, 4, 8 and 16. Run order P N N P P N N P, so 4 runs per arm and not 1 against 2. Each
    run uses the same bench.py (unique prompts, temperature 0, 3 repeats, medians) with 256 and 1,024 output tokens,
    cn_equal at every level and the 12 fixed answers. Check the thermal state before each run.
    • If N is slower than P beyond the P-against-P spread at 4 concurrent in 3 of the 4 pairs, bisect on the same pair:
      N with #4760 reverted (float32 g and beta in gated_delta_update); N with the sdpa_split route turned off (a
      local-only switch, after checking whether Qwen's verify windows reach it at all, as the refactor pass below argues
      they do not); and one Metal System Trace per arm at 4 concurrent (GPU busy share, command buffers per token, top
      kernels).
  2. Single Mac (the Studio), about 3 h: the models that carry OpenRouter traffic. Gemma 4 26B QAT, GPT-OSS 20B,
    Qwen3.5-9B, Qwen3.5-35B-A3B, Qwen3.6-35B-A3B, Nemotron 3.5 Lightning and Bonsai 2 9B, plus Nemotron 3.5 Super and
    MiMo V2.6 if the Studio holds them.
    Use the production settings (MTP auto, prefix cache on, sampled at the model defaults). Measure decode at 1, 4 and 8
    concurrent with 2K and 16K prompts, cold TTFT at 2K and 16K, and prefill at 3K and 11K. Order P N N P, with 3 repeats
    per cell. The Studio is an M3 Ultra and has no NAX, so if the window allows, repeat Gemma and Qwen3.6 for one hour on
    one M5 Ultra: the NAX kernels that #4741 renamed run only on M5.
    • Exactness on one Mac needs the deterministic setup: batch-invariance switch on, MTP at a fixed depth, temperature 0.
      The default setup is not reproducible run to run on either core, as "Single Mac" below shows. Compare the 12 fixed
      answers and cn_equal at 4 and 8 concurrent. Explain any difference by one of the upstream changes that alter bits
      by design (#4760, #4723, #4769, #4775); for a model with an unexplained difference, run a GPQA spot check (OpenRouter
      flags low GPQA).
  3. Clear it if no served model at any level is slower in per-request decode or TTFT by more than the larger of 2 %
    and its P-against-P spread, cn_equal holds everywhere, and every changed answer is explained. Otherwise keep it
    out of 0.10.12.

Release work if it clears:

  • A new metallib_hash. Take the expected hash from the final DevNet build's row and update the release kit's expected
    hash, docs/operations/provider-release.md, and the facts dry run's staged metallib (facts-dryrun stops on a
    mismatch). This PR reports that scripts/fetch-metallib.sh passes its completeness contract with #4741's new kernel
    names; check that again on DevNet.
  • The cluster runtime block's metallib_sha256 and native_runtime_sha256 change, and approvals are derived again
    (0.10.11's 24 plus 0.10.12's 24 is 48, within 64).
  • Re-record the bundled pair qualification records on this core with darkbloom-cluster-pair-check record, for every
    declared model and mode: Qwen3.8 27B, Qwen3.5-9B MTP modes, GLM-5.3-Flash, MiMo, and Gemma tensor parallel and pipeline.
    A record that becomes diverged withholds its family.
  • Run GLM5NextManagedLoadTests on a Metal Mac, as for 0.10.11.

Summary

The provider and cluster worker now build on upstream MLX main 1ba7f969 (2026-10-30), merged into the Layr-Labs forks. Speed is unchanged for Qwen3.8 27B and GLM-5.3-Flash, and outputs are byte-identical. Release builds no longer run MLX's debug-only work.

Gitlink Before After
libs/mlx 72dffa2d 47c5eb0e: Layr-Labs/mlx#49, upstream 1ba7f969 merged into the fork's main
libs/mlx-swift c633d221 86718def: Layr-Labs/mlx-swift#66, with the core above and Layr-Labs/mlx-c#20
libs/mlx-swift-lm 67110e7b (dev's pin) unchanged

Upstream since the last merge (34 commits):

  • sdpa_split kernels for speculative-decoding mid rows (#4723);
  • sliding window attention (#4734);
  • the quantized kernel instantiation cleanup (#4741);
  • float32 g and beta in gated_delta_update (#4760);
  • JACCL dead-link detection (#4767);
  • debug-build graph verification (#4711);
  • config::get;
  • fixes.

The NAX quantized kernels (#4712, #4709, #4682, #4654, #4640) were already in the previous pin.

Release builds and NDEBUG:

  • SwiftPM's release configuration did not define NDEBUG, so release builds ran the core's debug-only work.
  • With this core, that work includes #4711's graph check on every dispatch and allocation tracking on every malloc and free. It cost about 10% of decode until mlx-swift#66 defined NDEBUG for Cmlx in release.
  • Defining it also drops the core's asserts and Metal shader logging, as MLX's own CMake Release build does. On the previous core the define made no measurable difference.

Fork fixes in the merge (details in mlx#49):

  • the thread-scoped command-buffer limits, which the auto-merge had dropped;
  • a GPT-OSS kernel-name collision;
  • a template argument order;
  • allocator tracking under the process cap;
  • JACCL failure reasons and tests;
  • an mlx-c compile break;
  • two missing framework headers;
  • a use-after-free in the fork's expert-tile gathered matmul, found by upstream's new debug check in mlx-swift's CI on a GPU without neural accelerators. Without MLX_GATHER_QMM_EXPERT_SLICES=trust, the route's readback released the tile descriptors and the contiguous copies of the operands before the kernels that read them ran. Serving sets trust, which does not read back, and on M5 the neural-accelerator route takes these calls first.

Measured on two M5 Ultra 256 GB (TP2 over Thunderbolt 5 RDMA, encrypted and peer-verified)

Setup:

Build Qwen3.8 27B decode 256 / 1,024 Qwen c1 / c4 / c8 GLM-5.3-Flash decode 256 / 1,024 GLM c1 / c8
Previous core 79.1 / 66.1 68.6 / 91.7 / 96.8 102.2 / 100.8 113.1 / 150.7
New core without NDEBUG 71.8 / 59.8 62.5 / 84.4 / 91.0 89.2 / 88.6 102.8 / 141.2
New core (this PR) 81.5 / 66.5 68.4 / 87.0 / 94.8 94.9 / 102.6 113.0 / 148.1
Previous core with NDEBUG 81.3 / 65.5 68.8 / 91.2 / 96.4 101.4 / 98.4 112.9 / 148.4

Prefill (3K / 11K / 16K tokens):

  • Qwen: 1,447 / 1,433 / 1,405 against 1,455 / 1,442 / 1,412.
  • GLM: 3,140 / 3,981 / 4,006 against 3,100 / 3,964 / 4,052.

Noise: the GLM 256-token median ranges overlap (94.5–104.4 against 99.0–104.6). GLM's single-request decode p50 in cn_equal is 117.6 against 117.7.

Exactness, every run:

  • All 12 fixed answers of each model are byte-identical: Qwen against the branch.9 reference, GLM against the previous core.
  • Concurrent rows are byte-equal to solo at every level: Qwen c1–c8, GLM c1–c16.

Single Mac (GLM-5.3-Flash on Ultra A alone):

Single Mac Decode 256 / 1,024 (per run) Prefill 3K / 11K / 16K / 31K
Previous core 64.8, 71.0, 68.9 / 62.9, 65.5, 68.2 1,946 / 2,097 / 2,106 / 2,119
New core 61.7, 64.0, 68.9 / 62.9, 68.0, 64.2 1,954 / 2,115 / 2,128 / 2,120
  • Prefill: +0.4–1%.
  • Decode: within run-to-run noise (1,024-token means 65.5 against 65.0).
  • Reproducibility: single-Mac greedy answers are not reproducible in either build. Two more fresh-server runs of the 12 fixed answers matched their own build's first run on only 0–3 of 12, and two consecutive runs on one server matched on 0–1.
    • Single-Mac serving leaves the batch-invariance switch off, and its MTP depth adapts to timing.
    • So a single-Mac comparison of answers cannot detect a change; the reproducible gates are the tensor-parallel ones above.
    • This predates the change.

GLM-5.3-Flash images and video (TP2 on the pair, worker built from e881d5c2):

  • Compared with the official 0.10.4-dev.branch.9 build, run first in the same session: image kit 51 cases and video kit 15 cases, none newly failing or newly passing.
  • The 7 cases that fail on both builds are strict expectations in the kits (an exact answer to a hard number-reading question, an older refusal message), not product failures.
  • The 12 fixed GLM answers on that build are identical to the previous core's.
  • The last commit (976193e8) only changes a path that serving does not take, so these were not re-run on it.

Before

flowchart LR
  subgraph Code
    P1["provider / cluster worker"] --> S1["libs/mlx-swift c633d221"]
    S1 --> C1["core 72dffa2d (upstream main of 2026-10-23)"]
    S1 --> R1["SwiftPM release: NDEBUG not defined"]
  end
  subgraph Behavior
    B1["Qwen 27B TP2 decode 79.1 tok/s, GLM TP2 102.2 tok/s (256 tokens)"]
  end
Loading

After

flowchart LR
  subgraph Code
    P2["provider / cluster worker"] --> S2["libs/mlx-swift 86718def"]
    S2 --> C2["core 47c5eb0e = upstream main 1ba7f969 merged into the fork"]
    S2 --> R2["SwiftPM release: NDEBUG defined for Cmlx (no per-dispatch debug checks)"]
  end
  subgraph Behavior
    B2["Qwen 27B TP2 81.5 tok/s, GLM TP2 94.9-102.6 tok/s; outputs byte-identical"]
  end
Loading

Validation

Fork repos:

  • MLX C++ suite, Debug AOT and Release JIT: 342/342 with MLX_ENABLE_TF32=0. With TF32 on, 336/342: the same 6 linalg cases fail on unmodified upstream on NAX.
  • CPU 342/342; allocation cap 15/15; fence chains 3/3; qmv_batch_invariant passes.
  • JACCL: upstream's new unplug tests 14/14; tests/jaccl 14/14 under ASan+UBSan and under TSan.
  • mlx-c: build, ctest and startup-wait tests pass.
  • mlx-swift Fork Tests (all shards): XCTest 849 + 7 isolated tests with 0 failures; Swift Testing 749/749; every test ran once.
  • The same suite with the expert-tile route forced off the neural accelerators, as on the hosted runner: every test ran once, none failed. Before the last core fix, testGemmaGateUpSortedAffineGatherQuantizedMMExpertSlices stopped on the debug check there, as it did in CI.
  • clang-format 21.1.8 and cmake-format pass; check_forkdiff passes in all three repos.

This repo:

  • scripts/docs-impact-check.py --base origin/dev: coverage OK.
  • scripts/changelog.py check: passes.
  • scripts/docs-check.sh: 204 files OK.
  • The source-matched metallib (scripts/fetch-metallib.sh) builds and passes its completeness check.

Refactor pass

An independent review pass found no problem with the pins.

It checked every MLXFast.scaledDotProductAttention call site reachable from cluster and batched serving: contiguous and paged caches, Qwen TP, MiMo, GPT-OSS and the vision towers. Each call carries one sequence.

  • The only call with batch > 1 (attendUniformQueryBlocks) uses an array mask and 128-query blocks, so it cannot reach sdpa_split.
  • GLM text does not use this function.

It tightened the docs paragraph:

  • the full sdpa_split condition: at least 128 keys, no array mask or sinks, head dim, more than one KV head off NAX;
  • the function named;
  • prompt chunks added to the examples.

It corrected the changelog:

  • dropped sliding-window attention, which the provider cannot reach (mlx-c passes no window);
  • dropped the speculative attention kernels (no measured effect);
  • added the pin moves;
  • reworded the NDEBUG line so it implies no shipped regression.

I dropped one of its additions, a claim that the first start recompiles kernels, because nothing measured supports it.

It noted, outside this PR's scope:

  • docs/architecture/components/mlx-swift.md has a stale pin table;
  • libs/mlx-swift-lm/Package.swift still names mlx-swift c633d221. The provider's local path dependency overrides it, as before.

Limitations

  • Not a speed-up. The upstream NAX kernels were already in the previous pin.
  • Upstream #4781 is not included. It is still open upstream; it adds NAX split-K and a staged schedule for FP formats. It is being evaluated separately on the pair: it could speed GLM's NVFP4 dense prefill, and it does not touch Qwen TP decode, which runs its own exact kernels.
  • Merge order. The pins are the heads of mlx#49, mlx-c#20 and mlx-swift#66; merge those first, with merge commits (not squash or rebase), so the pinned commits stay on the forks' main.

@jonathan308
jonathan308 requested a review from davidtai October 30, 2026 15:31
@vercel

vercel Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Error Error Nov 8, 2026 8:02am UTC
d-inference-console-ui-dev Error Error Nov 8, 2026 8:02am UTC
d-inference-landing Ready Ready Preview Nov 8, 2026 8:02am UTC
darkbloom-status Ready Ready Preview Nov 8, 2026 8:02am UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 8, 2026 8:02am UTC

Request Review

@jonathan308
jonathan308 marked this pull request as draft October 30, 2026 16:06
jonathan308 and others added 3 commits November 7, 2026 23:58
libs/mlx and libs/mlx-swift's nested core move to Layr-Labs/mlx 70245518 (Layr-Labs/mlx#49), the merge of upstream MLX main 1ba7f969 (2026-10-30) into the fork's main, which contains the previous pin 72dffa2d. libs/mlx-swift moves to 19b72070 (Layr-Labs/mlx-swift#66): the new core and C layer (Layr-Labs/mlx-c#20), regenerated sources, and NDEBUG in release builds of Cmlx, without which upstream's new per-dispatch debug checks ran in release builds and cost about 10% of decode.

Measured on two M5 Ultra 256 GB, tensor parallel, one session, with only MLX differing (worker built from #1680): Qwen3.8 27B decode 81.5 / 66.5 tok/s (256 / 1,024 tokens) against 79.1 / 66.1, GLM-5.3-Flash 94.9 / 102.6 against 102.2 / 100.8 (run-to-run noise: GLM c1 decode p50 117.6 against 117.7), prefill unchanged. The 12 fixed greedy answers of each model are byte-identical, and concurrent rows equal solo at every level (Qwen c1-c8, GLM c1-c16).

docs/architecture/inference.md records that the cluster's MLX attention calls must keep one sequence per call: upstream's sdpa_split picks its key blocks from the batch size. A changelog fragment follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libs/mlx and the nested core move to 15dd4571 (Layr-Labs/mlx#49) and libs/mlx-swift to 00505522 (Layr-Labs/mlx-swift#66, nested mlx-c 2db89819 of Layr-Labs/mlx-c#20). The core's three commits since 70245518 are fixes. In the expert-tile gathered matmul, the tile descriptors now stay alive for the tile kernel when MLX_GATHER_QMM_EXPERT_SLICES is not trust; serving sets trust. Two sealed all-sum names no longer read as MLX ops to the stream-argument lint. Two upstream tests run on the GPU only. Kernel sources and the metallib are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libs/mlx and the nested core move to 47c5eb0e (Layr-Labs/mlx#49) and libs/mlx-swift to 86718def (Layr-Labs/mlx-swift#66, nested mlx-c ba493a03 of Layr-Labs/mlx-c#20). The core's one new commit is a fix: with MLX_GATHER_QMM_EXPERT_SLICES set but not to trust, the expert-tile gathered matmul's readback no longer frees the contiguous copies of its operands before the kernels that read them run. Serving sets trust, and on M5 the neural-accelerator route takes these calls first. Kernel sources and the metallib are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fragment named the mlx-swift-lm pin of the dev this branch was first
based on. After the rebase onto dev d9d36fe, the branch leaves dev's pin
67110e7b unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch had an error being deployed

2 failed and 3 active deployments
Preview – d-inference-landing — f6d86253 Deployed Nov 8, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — f6d86253 Deployed Nov 8, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — f6d86253 Deployed Nov 8, 2026 by vercel[bot]
Preview – darkbloom-status — f6d86253 Deployed Nov 8, 2026 by vercel[bot]
Preview – d-inference — f6d86253 Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant